Industries such as the petrochemical industry often require precise measurements of trace gases within background gases to ensure that concentrations of such trace gases are within acceptable limits. Compliance with these limits in turn can be used to verify factors such as whether the delivered gases meet certain purity limits and/or whether emissions of such gases comply with environmental regulations. In some cases, optical sensors utilizing harmonic spectroscopy have been used to measure concentrations of trace gases. However, pressure variations in samples of gas delivered to optical sensors can distort second harmonic signals thereby resulting in inaccurate measurements.